﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication27
{
    class io
    {

      



            public byte[] wczytaj(string path)
            {
                

                FileStream fs = null;
              

                    fs = new FileStream(path, FileMode.Open);
              

                BinaryReader br = new BinaryReader(fs);
                byte[] inputFile = new byte[(int)br.BaseStream.Length];
                br.Read(inputFile, 0, (int)br.BaseStream.Length);

                br.Close();
                fs.Close();

                return inputFile;


            }

            public byte[] wczytaj2(string path)
            {
               

                FileStream fs = null;


                fs = new FileStream(path, FileMode.Open);


                BinaryReader br = new BinaryReader(fs);
                byte[] inputFile = new byte[(int)br.BaseStream.Length];
                br.Read(inputFile, 0, (int)br.BaseStream.Length);

                br.Close();
                fs.Close();

                return inputFile;


            }

            public List<string> wczytajklucze()
            {
                List<string> temp = new List<string>();
           
                TextReader tr = new StreamReader("@klucze.txt");
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                tr.Close();

                return temp;             
            }

            public List<string> wczytajklucze(string path)
            {
                List<string> temp = new List<string>();

                TextReader tr = new StreamReader(path);
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                temp.Add(tr.ReadLine());
                tr.Close();

                StreamWriter sw = new StreamWriter("@klucze.txt");
                sw.WriteLine(temp[0]);
                sw.WriteLine(temp[1]);
                sw.WriteLine(temp[2]);
                sw.WriteLine(temp[3]);
                sw.WriteLine(temp[4]);
                sw.Close();


                return temp;
            }



            public void zapisz(List<Liczba> temp, string path)
            {
                int rozmiar = 0;
                foreach (Liczba u in temp)
                {
                    foreach (ulong x in u.element)
                        rozmiar++;
                }



                byte[] w=new byte[rozmiar];
                int i = 0;
                foreach(Liczba u in temp )
                {
                    foreach (ulong x in u.element)
                    w[i++] = (byte)x;
                }

              
              
                    FileStream fs2 = new FileStream(path, FileMode.Create);
                    BinaryWriter bw = new BinaryWriter(fs2);
                   
                        bw.Write(w);
                    
                    bw.Close();
                    fs2.Close();
               
            }

            public void zapiszklucze(string n,string e,string d,string p,string q)
            {
                try
                {
                    StreamWriter sw = new StreamWriter("@klucze.txt");
                    sw.WriteLine(n);
                    sw.WriteLine(e);
                    sw.WriteLine(d);
                    sw.WriteLine(p);
                    sw.WriteLine(q);
                    sw.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: " + ex.Message);
                }
               

            }




       




    }
}
